home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / stnvjw23.zip / SETENV.DOC < prev    next >
Text File  |  1993-09-10  |  12KB  |  291 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.         SETENV utility V2.3 (c) 09-Sep-1993 
  7. The SETENV program for a DOS version 2 allows setting an 
  8. environment variable.  SETENV utility will run under DOS 
  9. 3.30 thru 4.0, 5.0, and 6.0.  I have not seen DOS V1.x.  
  10.  
  11. SETENV : Copyright (c) 1988 to 1993 by John Wolchak.  
  12.   I give permission to alter the code, but not to copy 
  13.   or redistribute the altered code without my explicit 
  14.   permission.  If you alter the code, please document 
  15.   changes and send me a copy, so all can have it.  
  16.   This document must always accompany the SETENV 
  17.   program when a copy is made for another machine.  
  18.   This code, to the best of my knowledge works well.  
  19.   I disclaim any responsibility for the codes actions 
  20.   (use at your own risk).  
  21.                         John 
  22.  
  23. The syntax of the command is: 
  24.  
  25.     SETENV <variable> <value> 
  26.  
  27. <variable> is any valid environment variable you wish to 
  28. define or re-define.  
  29.  
  30. <value> is a string of printable characters.  Keys can be 
  31. embedded in the character string.  The Keys are: 
  32.   %cwd will return the current working directory.  ie. \bin 
  33.   %cfd will return the current full directory specification.  ie. \bin\ 
  34.   %date will return the curent date.  
  35.   %dosv will return the DOS major version.  
  36.   %dosm will return the DOS minor version.  
  37.   %drive will return the current disk drive letter.  
  38.   %time will return the cuurent time.  
  39.   %-n will return the current disk drive minus 'n' letter(s).  
  40.   %+n will return the current disk drive plus 'n' letter(s).  
  41.  
  42. <value> can have special keys embedded in the character string.  
  43. Special Keys are keys that have arguments, and they are: 
  44.   %chr<del><number><del> will return the character for ascii code.  
  45.   %loc<del><number><del><variable><del><text><del> will return the location 
  46.     for <text> in an environment <variable> starting at postion <number>.  
  47.   %mid<del><variable><del><number1><del><number2><del> will return a string 
  48.     of length <number2> in an environment <variable> starting at <number1>.
  49.   %elem<del><number><del><character><del><variable><del> will return the 
  50.     <number> element in a string of elements from environment <variable>.  
  51.   %len<del><variable><del> will return the length of the data portion of 
  52.     environment <variable>.  
  53.   %sum<del><variable><del><number><del> will return the sum of an 
  54.     environment <variable> and a <number>.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. <value> can be '%<operator> [<string>|<variable>]  [<string>|<variable>]' 
  62. For example:    setenv ans %eq 'JOHN' name    setenv ans %eq name "JOHN" 
  63. The returned environment value is T for true and F for false, and if there 
  64. is an error, then E is returned.  The arguments can be a quoted string of 
  65. characters, or a variable name.  Leading spaces will be trimed from the 
  66. arguments before testing.  Strings are quoted with single or double quotes.  
  67. <operator> can be: 
  68.   %eq will test if two arguments are equal.  
  69.   %lt will test if argument one is less than argument two.  
  70.   %le will test if argument one is less than or equal to argument two.  
  71.   %gt will test if argument one is greater than argument two.  
  72.   %ge will test if argument one is greater than or equal to argument two. 
  73.  
  74.  
  75. <value> can be '%rep<del><text1><del><text2><del>', where <text1> 
  76.     will replace <text2> in the environment variable value.
  77.  
  78. <value> can be '%chgup' which will uppercase the existing 
  79.     environment <variable>.  
  80.  
  81. <value> can be '%chglo' which will lowercase the existing 
  82.     environment <variable>.  
  83.  
  84. <value> can be '%prompt <message>'.  
  85. <value> can be '%prompt %readkey <message>'.  
  86. <value> can be '%prompt %def<del><text><del> <message>'.  
  87. <value> can be '%prompt %def<del><text><del> %timo=hh:mm:ss <message>'.  
  88. <value> can be '%prompt %upper %def<del><text><del> %trim <message>'.  
  89. <value> can be '%prompt %noecho %lower %def<del><text><del> <message>',  
  90. where the <message> is displayed on the console and the response is set 
  91. into the <variable>.  %def is optional, and <text> is the <value> used, 
  92. if just a return is given.  <del> is a one character delimter, to quote 
  93. the <text>.  %noecho is optional meaning not to display the response on 
  94. the screen (ie. passwords).  %upper is optional meaning to convert the 
  95. lower case letters to upper case letters.  %lower is optional meaning 
  96. to convert the upper case letters to lower case letters.  %trim is optional 
  97. meaning to trim leading and trailing spaces.  %timo is optional meaning 
  98. to time out the prompt message and exit after hh:mm:ss.  %readkey is to 
  99. read one key stroke without needing the carriage return.
  100.  
  101. <message> is the message display for a prompt.  <message> can have 
  102. %/<number>/ embedded in the string to create a character that DOS will 
  103. not allow you to enter on the command line directly. ie for <number> 
  104. 60 will create < and 124 creates | and 62 creates >.  
  105.  
  106. No %timo means to prompt forever.  No %def and a %timo will assume %def//.  
  107. The time out is for the first character entered, after the first character 
  108. is entered you have forever to enter the rest of the text.  
  109.  
  110.  
  111.  
  112. Note: In batch (BAT files) use %% to represent a single % for use 
  113. to SETENV.   ie. SETENV DRV_DIR %%drive:%%cwd 
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. Note:  SETENV can not expand the environment space.  The DOS SET 
  121. command can do that, by creating temporary variables with long 
  122. values and then removing them before any resident program is run.  
  123. Resident programs are PRINT, MODE.  Documentation is available for 
  124. versions of DOS 2 thru 3.20 that modify DOS to have a larger 
  125. environment area beyond the normal 160 bytes.  For DOS 3.30 and 
  126. above use the shell /E:xxxx option, of Config.Sys.  
  127.  
  128.  
  129.  
  130. SETENV terminates with int 21h, AH=4ch, the intention is that SETENV can 
  131. be called from another program, and the return codes can be tested.  
  132.  
  133.  
  134. SETENV returns errorlevel codes, which are: 
  135.  
  136.     no command, help issued        00h 
  137.     root environment set        01h 
  138.     environment variable erased    02h 
  139.     environment variable created    03h 
  140.     don't know about MS-DOS V1.x    04h 
  141.     environment variable updated    05h 
  142.     unmatched delimiter        06h 
  143.     not a valid argument        07h 
  144.     environment variable not found    08h 
  145.     offset of drive will be invalid    09h 
  146.     environment space is full    10h 
  147.  
  148. Code 04h has changed to report that we are using MS-DOS 
  149. version one.  Code 07h has been changed to report that 
  150. the argument used is not the valid type for use.  Usually 
  151. that will mean that the argument is not numeric.  
  152.  
  153.  
  154.  
  155. Example uasge: 
  156.  
  157. This example batch file can demonstrate the usage of SETENV.  
  158.  
  159. setenv version MS-DOS V%%dosv.%%dosm in %%drive:%%cwd drv/dir. 
  160. setenv drvs Drive is %%+0:, with %%-1: prev and %%+1: next. 
  161. setenv first %%prompt Your First Name: 
  162. setenv last %%prompt %first% Your Last Name: 
  163. setenv answer %%prompt %%def/Y/ %first% %last% [Y/N] <Y>: 
  164. set 
  165.  
  166. First note the %% for a single % in batch.  In batch you can 
  167. use %<environ_var>% to reflect the value of a previous 
  168. environment variable.  Make sure you have enough environment 
  169. space to store this amount of data.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. History: 
  177.  
  178. At work we have Disk and File Serving using DOS version 3.  
  179. When a machine optionally has or hasn't a hard disk, one or 
  180. more hard disk partitions and maybe a ramdisk, locating the 
  181. disk or file server is a little tricky.  The disk and file 
  182. servers are located after your hard disk partitions.  To find 
  183. them we copy a file, to a redefined disk.  Then test to see if 
  184. the file exists.  If the file exists, then what drive are we on.  
  185. Example is: 
  186.     assign b=g >nul 
  187.     assign b=h >nul 
  188.     assign b=i >nul 
  189.     assign b=j >nul 
  190.     assign b=k >nul 
  191.     copy command.com b:\ 
  192.     assign b=b >nul 
  193.     if not exist k:\command.com goto jdrv 
  194.     ... 
  195.     jdrv: 
  196.     if not exist j:\command.com goto idrv 
  197.     ... 
  198.     idrv: 
  199.     ... 
  200.     ... 
  201.  
  202. (We no longer do this now that we have SETENV.) 
  203.  
  204.  
  205. I wrote a program called CURDRV.  This program would put the 
  206. current disk drive letter in an environment variable called 
  207. CURDRV.  The first problem was that when I set the environment 
  208. variable, then exited the program it was gone, because a 
  209. program has a copy of the environment space.  
  210.  
  211. Th